package com.example.ppjoke.frame;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.ppjoke.R;
import com.example.ppjoke.frame.dynamicnav.AppBottomView;
import com.example.ppjoke.frame.dynamicnav.NavigationBuilder;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import org.jetbrains.annotations.NotNull;

@Route(path = "/app/frameactivity")
public class FrameActivity extends AppCompatActivity {

    private AppBottomView appBottomView;
    private NavHostFragment fragment;
    private NavController controller;
    @Override
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        appBottomView = findViewById(R.id.app_bottom);
        fragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.host_fragment);
        controller = fragment.getNavController();
        new NavigationBuilder().create(this,getSupportFragmentManager(),controller,fragment.getId());
//        appBottomView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
//            @Override
//            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
//
//            }
//        });
        appBottomView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull @NotNull MenuItem item) {
                controller.navigate(item.getItemId());
                return true;
            }
        });
    }
}
